//
//  HCMessageShopSysView.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/19.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCMessageShopSysView.h"

#import "HCMsgCenterModel.h"


@interface HCMessageShopSysView () {
    HCMsgCenterData *data;
}

@property (nonatomic, copy) NSString *promptString;

@end

@implementation HCMessageShopSysView

-(instancetype)initWithFrame:(CGRect)frame andPromptString:(NSString *)str dataID:(id)model{
    if (self = [super initWithFrame:frame]) {
        self.promptString = str;
        [self initializeSubViews:frame data:model];
    }
    return self;
}

-(void)initializeSubViews:(CGRect)frame data:(id)model{
    
    data = (HCMsgCenterData *)model;
    
    //消息名称
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, frame.size.width-25, 30/2.0)];
    nameLabel.textColor = [UIColor darkGrayColor];
    nameLabel.font = [UIFont systemFontOfSize:15];
    [self addSubview:nameLabel];
    
    //消息内容
    UIView *contentBG = [UIView new];
    contentBG.backgroundColor = YBKRGBCOLOR(232, 232, 232, 1);
    [self addSubview:contentBG];
    
    NSString *str = [NSString stringWithFormat:@"%@",data.text];
    
    NSLog(@"本内容:%@",str);
    
    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, nameLabel.frame.origin.y+nameLabel.frame.size.height+10, frame.size.width-50-8, 300)];
    contentLabel.font = [UIFont systemFontOfSize:13];
    contentLabel.text = str;
    contentLabel.numberOfLines = 0;
    contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
//    contentLabel.backgroundColor = YBKRGBCOLOR(232, 232, 232, 1);
    contentLabel.textColor = [UIColor darkGrayColor];
    
    //计算高度
    CGSize labelSize = [contentLabel sizeThatFits:CGSizeMake(contentLabel.frame.size.width, MAXFLOAT)];
    contentBG.frame = CGRectMake(contentLabel.frame.origin.x, contentLabel.frame.origin.y, contentLabel.frame.size.width+8, labelSize.height+8);
    contentBG.layer.cornerRadius = 5.0f;
    
    //重置label的高度
    contentLabel.frame = CGRectMake(4, 4, contentLabel.frame.size.width, labelSize.height);
    
    [contentBG addSubview:contentLabel];
    
    if ([self.promptString isEqualToString:@"system"]) {
        nameLabel.text = @"系统消息";
    }else if ([self.promptString isEqualToString:@"shop"]) {
        nameLabel.text = [NSString stringWithFormat:@"%@",data.name];
//        UIImage *image;
//        if ([data.stat integerValue] == 0) {
//            image = [UIImage imageNamed:@"确认付款g"];
//        }else{
//            //添加按钮
//            image =[UIImage imageNamed:@"happy_message_surePay"];
//        }
        

//        CGSize imageSize = image.size;
        
//        //确认付款按钮
//        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//        button.frame = CGRectMake(frame.size.width - imageSize.width - 25, contentBG.frame.origin.y+contentBG.frame.size.height+15, imageSize.width, imageSize.height);
//        [button setBackgroundImage:image forState:UIControlStateNormal];
//        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
//        
//        if ([data.stat integerValue] == 0) {
//            button.userInteractionEnabled = NO;
//        }else{
//            button.userInteractionEnabled = YES;
//        }
//        
//        [self addSubview:button];
        
    }
}

-(void)buttonAction:(UIButton *)btn {
    NSLog(@"确认付款");
    if ([self.delegate respondsToSelector:@selector(surePay:)]&&self.delegate) {
        [self.delegate surePay:data.hc_id];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
